//
//  WBNavigationController.swift
//  新浪微博
//
//  Created by 陈飞宇 on 2020/9/24.
//

import UIKit

class WBNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //隐藏默认的NavigationBar
        navigationBar.isHidden = true;
        
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true;
          
            //左侧返回按钮  子控制器为1时 显示首页控制器的名字
            if let vc = viewController as? WBBaseViewController {
                var title = "返回"
                if viewControllers.count == 1 {
                    title = viewControllers.first?.title ?? "返回"
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(goBack), isBack: true);
            }
        }
    
        
        super.pushViewController(viewController, animated: animated);        
    }
    
    @objc private func goBack() {
        popViewController(animated: true)
    }
    
    
}
